package net.ib.mtalk.ui.dialog;

import java.util.ArrayList;

import net.ib.mtalk.ui.inbox.InboxListActivity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

public class DialogMenu implements OnClickListener{

	public static InboxListActivity inboxActivityContext;
	
	AlertDialog mDialog;
	
	private DialogAdapter mAdapter;
	private Context mContext;
	private ArrayList<DialogListItem> mItem;
	
	public DialogMenu(Context context, ArrayList<DialogListItem> item){
		mContext = context;
		mItem = item;
	}
	
	public Dialog createDialog(){
		AlertDialog.Builder builder = null;
		
		if(mItem != null){
			mAdapter = new DialogAdapter(mContext, mItem);
		}
		builder = new AlertDialog.Builder(mContext);
		builder.setAdapter(mAdapter, this);
		builder.setInverseBackgroundForced(true);
		mDialog = builder.create();
		
		return mDialog;
	}
	
	@Override
	public void onClick(DialogInterface dialog, int which) {
//		((DialogListItem)this.mDialog.getListView().getAdapter().getItem(which)).actionTag);
		DialogMenuOnClickListener listener = (DialogMenuOnClickListener) mContext;
		listener.onClickDailogMenu(mItem.get(which), 
				((DialogListItem)this.mDialog.getListView().getAdapter().getItem(which)).actionTag);
	}

}
